package com.example.demo.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class Consumer {
    /*private static final Logger log = LoggerFactory.getLogger(Consumer.class);


    //消费者：监听topic1，groupId1
    @KafkaListener(topics = {"user"},groupId = "groupId1")
    public void consumer1(ConsumerRecord<Integer,String> record){
        log.info("consumer1 kfk consume message start...");
        log.info("consumer1 kfk consume message topic:{},msg:{}",record.topic(),record.value());
        log.info("consumer1 kfk consume message end...");
    }

    //消费者：监听topic1，groupId2
    @KafkaListener(topics = {"user"},groupId = "groupId2")
    public void consumer2(ConsumerRecord<Integer,String> record){
        log.info("consumer2 kfk consume message start...");
        log.info("consumer2 kfk consume message topic:{},msg:{}",record.topic(),record.value());
        log.info("consumer2 kfk consume message end...");
    }
    //消费者：监听topic1，groupId3
    @KafkaListener(topics = {"user"},groupId = "groupId3")
    public void consumer3(ConsumerRecord<Integer,String> record){
        log.info("consumer3 kfk consume message start...");
        log.info("consumer3 kfk consume message topic:{},msg:{}",record.topic(),record.value());
        log.info("consumer3 kfk consume message end...");
    }*/
}
